<template>
	<view class="addEditForm">
		<view class="data-form bgfff">
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">物品名称</text>
				<view class="data-form-input">
					<input type="text" :disabled="optionDisabled" v-model="dataForm.name"
						:placeholder="optionDisabled?'-':'请输入物品名称'" placeholder-class="plStyle" />
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">数量</text>
				<view class="data-form-input">
					<input type="text" :disabled="optionDisabled" v-model="dataForm.quantity"
						:placeholder="optionDisabled?'-':'请输入数量'" placeholder-class="plStyle" />
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">单位</text>
				<view class="data-form-input">
					<input type="text" :disabled="optionDisabled" v-model="dataForm.unit"
						:placeholder="optionDisabled?'-':'请输入单位'" placeholder-class="plStyle" />
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">生产日期</text>
				<view class="data-form-input">
					<cpdd-date v-model="dataForm.produceTime" :disabled="optionDisabled" :isTime="false"></cpdd-date>
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">过期日期</text>
				<view class="data-form-input">
					<cpdd-date v-model="dataForm.expireTime" :disabled="optionDisabled" :isTime="false"></cpdd-date>
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">食品类型</text>
				<view class="data-form-input">
					<cpdd-select v-model="dataForm.fType" @change="typeChange" :disabled="optionDisabled"
						:list="foodTypeList" keyname="name" valname="val"></cpdd-select>
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">子类型</text>
				<view class="data-form-input">
					<cpdd-select v-model="dataForm.fTypeSub" @change="typeChildChange" :disabled="optionDisabled" :list="foodChildTypeList"
						keyname="typeName" valname="id"></cpdd-select>
				</view>
			</view>
			<view class="data-form-item flex-ac">
				<text class="data-form-label f30">是否进口</text>
				<view class="data-form-input gui-flex gui-justify-content-end">
					<radio-group @change="radioChange">
						<label class="radio">
							<radio value="1" style="transform: scale(0.7);"  />是
						</label>
						<label class="radio">
							<radio value="0" style="transform: scale(0.7);" checked="true" />否
						</label>
					</radio-group>
					<!-- <input type="text" :disabled="optionDisabled" v-model="dataForm.whetherImport"
						:placeholder="optionDisabled?'-':'请输入是否进口'" placeholder-class="plStyle" /> -->
				</view>
			</view>

		</view>
		<view class="right-area-footer2 flex-ac bgfff" v-if="!optionDisabled">
			<view class="saveBtn cancleBtn" @tap="handleCancle">取消</view>
			<view class="saveBtn" @tap="handleSubmit">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				did: '',
				dataForm: { //表单
					name: '',
					quantity: '',
					unit: '',
					produceTime: '',
					expireTime: '',
					fType: '',
					fTypeName: '',
					fTypeSub: '',
					fTypeSubName: '',
					whetherImport: 0,
				},
				cpddDateRangeVal: '',
				cpddDateRangeVal2: '',
				selectList: [], //上一页带过来，如果上一页用不到，可以在这里调用赋值
				foodChildTypeList: [],
				optionDisabled: false,
				foodTypeList: [{
						name: '食品',
						val: 'Food'
					},
					{
						name: '食用农产品',
						val: 'FoodFarm'
					},
					{
						name: '食品添加剂',
						val: 'FoodAdd'
					},
					{
						name: '食品相关',
						val: 'FoodRelate'
					}
				],
			}
		},
		onLoad(options) {
			console.log('options', options);
			this.did = options.id || ''
			this.optionDisabled = options.op == 'look' ? true : false
			let title = options.op == 'look' ? '详情' : options.op == 'add' ? '商品录入' : '编辑'
			uni.setNavigationBarTitle({
				title
			})
		},
		methods: {
			radioChange(e) {
				console.log(e);
				e.detail.value
			},
			typeChange(e) {
				this.dataForm.fTypeName = this.foodTypeList.filter(item => item.val == e)[0].name;
				this.selectChildType(e);
			},
			typeChildChange(e) {
				this.dataForm.fTypeSubName = this.foodChildTypeList.filter(item => item.id == e)[0].typeName;
			},
			selectChildType(parentType) {
				this.$http.get('/material/foodType/list', {
					pageNum: 1,
					pageSize: 9999,
					parentType
				}).then(res => {
					let result = res.rows
					this.foodChildTypeList = result;
				})
			},
			handleCancle() {
				this.$u.back()
			},
			handleSubmit() {
				console.log('提交');
				if(!this.dataForm.name) return this.$u.msg('请输入物品名称')
				if(!this.dataForm.quantity) return this.$u.msg('请输入数量')
				if(!this.dataForm.unit) return this.$u.msg('请输入单位')
				if(!this.dataForm.produceTime) return this.$u.msg('请选择生产日期')
				if(!this.dataForm.expireTime) return this.$u.msg('请选择过期日期')
				if(!this.dataForm.fType) return this.$u.msg('请选择食品类型')
				if(!this.dataForm.fTypeSub) return this.$u.msg('请选择食品子类型')
				uni.$emit('reFGoodsList', this.dataForm)
				this.$u.back(1, 200)
			}

		}
	}
</script>

<style>

</style>